package com.linkage.educloud.ah.mvp;

import com.linkage.educloud.ah.http.Method;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;
import com.zhouyou.http.subsciber.BaseSubscriber;

import io.reactivex.Observable;

/**
 * <desc>
 * Created by The Moss on 2018/11/29.
 */

public class CommonPresenter extends ICommonContract.IPresenter {
    ICommonContract.IModel iModel;
    public CommonPresenter(IBasicView iView) {
        super(iView);
        iModel = new CommonModel();
    }

    @Override
    public void request(HttpParams params) {
        Observable observable = iModel.request(Method.POST,true,params);
        observable.compose(iView.bindLifecycle())
                .subscribe(new BaseSubscriber<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ((ICommonContract.IView)iView).onFailResult("");
                    }

                    @Override
                    public void onNext(String s) {
                        ((ICommonContract.IView)iView).onSuccessResult(s);
                    }
                });
    }
}
